<template>
  <div>
    <Chart :cdata="cdata" />
  </div>
</template>

<script>
import Chart from './chart.vue'
import * as DataApi from "@/http/DataApi.js";
export default {
  data () {
    return {
      cdata: {
        category: [],
        lineData: [],
        barData: [],
        rateData: []
      }
    };
  },
  components: {
    Chart,
  },
  mounted () {
      DataApi.getTransaction().then((res) => {
          this.cdata.category=res.data.name;
          this.cdata.barData=res.data.finish;
          this.cdata.lineData=res.data.estimate;
          this.setData();
          this.cdata={...this.cdata}
      });

  },
  methods: {
    // 根据自己的业务情况修改
    setData () {
      for (let i = 0; i < this.cdata.barData.length ; i++) {
        let rate = this.cdata.barData[i] / this.cdata.lineData[i];
        this.cdata.rateData.push(rate.toFixed(2));
      }
    },
  }
};
</script>

<style lang="scss" scoped>
</style>
